package demo1;
/*
class Dog {
    public String name;
    public int age;

    public void eat() {
        System.out.println(this.name + "正在吃");
    }
    public void bark() {
        System.out.println(this.name + "汪汪汪！");
    }
}

class Cat {
    public String name;
    public int age;

    public void eat() {
        System.out.println(this.name + "正在吃");
    }

    public void miao() {
        System.out.println(this.name + "正在喵喵");
    }
}

public class TestDemo {
    public static void main(String[] args) {
        Dog dog1 = new Dog();
        dog1.name = "元宝";
        dog1.age = 4;
        dog1.eat();
        dog1.bark();
        System.out.println("==========");
        Cat cat1 = new Cat();
        cat1.name = "黑豹";
        cat1.age = 12;
        cat1.eat();
        cat1.miao();
    }

}*/

//继承：对共性进行抽取，把抽取出来的共性放到父类当中；好处：达到了代码的复用
//父类/基类/超类
class Animal {
    public String name;
    public int age;

    static {
        System.out.println("Animal静态代码块！");
    }

    {
        System.out.println("Animal构造代码块！");
    }

    public Animal() {
        System.out.println("Animal不带参数的构造方法！");
    }
    public Animal(String name, int age) {
        this.name = name;
        this.age = age;
    }
    public void eat() {
        System.out.println(this.name + "正在吃");
    }
}

class Dog extends Animal{
    String color;
//    public Dog() {
//        super("元宝",4);
//    }

    public Dog() {
        System.out.println("Dog不带参数的构造方法！");
    }
    public Dog(String name,int age,String color) {
        super(name,age);
        this.color = color;
    }

    static {
        System.out.println("Dog静态代码块！");
    }

    {
        System.out.println("Dog构造代码块！");
    }
    public void bark() {
        System.out.println(this.name + "汪汪汪！");
    }
}

//子类/派生类
class Cat extends Animal{
    public Cat() {
        System.out.println("不带参数的构造方法Cat");
    }

    static {
        System.out.println("Cat静态代码块！");
    }

    {
        System.out.println("Cat构造代码块！");
    }
    public void miao() {
        System.out.println(this.name + "正在喵喵");
    }
}

public class TestDemo {
    public static void main(String[] args) {
        Dog dog = new Dog();
        System.out.println("=========");
        Cat cat = new Cat();
    }


    public static void main1(String[] args) {
        Dog dog1 = new Dog("元宝",4,"黑白");
        dog1.name = "元宝";
        dog1.age = 4;
        dog1.eat();
        dog1.bark();
        System.out.println("==========");
        Cat cat1 = new Cat();
        cat1.name = "黑豹";
        cat1.age = 12;
        cat1.eat();
        cat1.miao();
    }

}